package com.scs.application.modules.dept.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.base.annotation.MatrCanPass;
import com.scs.application.modules.dept.entity.ApplyItem;
import com.scs.application.modules.dept.entity.DemandItem;
import com.scs.application.modules.dept.service.DemandItemService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 科室需求计划明细 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/dept/demandItem")
public class DemandItemController extends CrudController<DemandItemService, DemandItem>{

    /**
     * @Description： 批量保存模板
     */
    @PostMapping("/saveBatchPackage")
    public RestResult saveBatchPackage(@Valid @RequestBody List<DemandItem> entityList) {
        service.saveBatchPackage(entityList);
        return RestResult.ok("批量添加成功");
    }


    /**
     * @Description：采购需求批量操作
     */
    @PostMapping("/saveBatchForPurchaseDemand")
    public RestResult saveBatchForPurchaseDemand(@Valid @RequestBody List<DemandItem> entityList) {
        service.saveBatchForPurchaseDemand(entityList);
        return RestResult.ok("批量添加成功",  entityList);
    }


    /**
     * 添加/更新数据
     */
    @PostMapping("/save")
    @MatrCanPass(businessType = "demand_item")
    public RestResult saveItem(@Valid @RequestBody DemandItem entity) {
        boolean isOk = service.saveOrUpdate(entity);
        if (!isOk) {
            return RestResult.error("数据保存失败");
        }
        return RestResult.ok("数据保存成功", entity);
    }

}
